package libsys.listeners;

import libsys.general.LIBSYSSystem;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;

public class NavigationTreeListener implements TreeSelectionListener
{
		LIBSYSSystem LibrarySystem;
		
		public NavigationTreeListener(LIBSYSSystem LibrarySystem)
		{
				this.LibrarySystem = LibrarySystem;
		}
		
		public void valueChanged(TreeSelectionEvent te)
		{
				TreePath path = LibrarySystem.FrameItems.navigationFrameItems.navigation_tree.getSelectionPath();
				
				DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent();
				
				String leaf = node.getUserObject().toString();
				
				if(leaf.equals("Borrowings"))
				{
						LibrarySystem.loadNavigationBooksBorrowingsPanel();
				}
				
				if(leaf.equals("Returns"))
				{
						LibrarySystem.loadNavigationBooksReturnsPanel();
				}
		}	
}